﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace ARS.Common.Service.Model
{
    
    /// <summary>
    /// 业务返回类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BizResult<T>
    {
        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 调用是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 业务代码
        /// </summary>
        public EnumBizCode Code { get; set; }

        /// <summary>
        /// 返回结果
        /// </summary>
        public T ReturnObj { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="isSuccess">是否成功</param>
        /// <param name="bizCode">业务代码</param>
        public BizResult(bool isSuccess, EnumBizCode bizCode)
        {
            IsSuccess = isSuccess;
            Code = bizCode;
            Message = bizCode.ToString();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="isSuccess">是否成功</param>
        /// <param name="bizCode">业务代码</param>
        /// <param name="message"></param>
        public BizResult(bool isSuccess, EnumBizCode bizCode, string message)
        {
            IsSuccess = isSuccess;
            Code = bizCode;

            //提示信息，不默认加错误码的描述信息
            //Message = bizCode.ToDescription();
            if (!string.IsNullOrWhiteSpace(message))
            {
                Message += " " + message;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="returnObj">返回对象类型</param>
        /// <param name="isSuccess">是否成功（默认成功）</param>
        /// <param name="bizCode">业务代码（默认Sucess）</param>
        public BizResult(T returnObj, bool isSuccess = true, EnumBizCode bizCode = EnumBizCode.Success)
        {
            ReturnObj = returnObj;
            IsSuccess = isSuccess;
            Code = bizCode;
            Message = bizCode.ToString();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="returnObj">返回对象类型</param>
        /// <param name="isSuccess">是否成功（默认成功）</param>
        /// <param name="bizCode">业务代码（默认Sucess）</param>
        /// <param name="message"></param>
        public BizResult(T returnObj, bool isSuccess, EnumBizCode bizCode, string message)
        {
            ReturnObj = returnObj;
            IsSuccess = isSuccess;
            Code = bizCode;

            //提示信息，不默认加错误码的描述信息
            //Message = bizCode.ToDescription();

            if (!string.IsNullOrWhiteSpace(message))
                Message += " " + message;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BizResult()
        { }
    }
    /// <summary>
    /// 业务CODE
    /// </summary>
    public enum EnumBizCode
    {
        /// <summary>
        /// 成功
        /// </summary>
        [Description("成功")]
        Success = 1000,

        /// <summary>
        /// 操作失败
        /// </summary>
        [Description("操作失败")]
        Failed = 4000,

        /// <summary>
        /// 程序错误
        /// </summary>
        [Description("程序错误")]
        Exception,

        /// <summary>
        /// 无效参数
        /// </summary>
        [Description("无效参数")]
        InvalidParameter,

        /// <summary>
        /// 自定义内容
        /// </summary>
        [Description("")]
        CustomContent
    }
}
